package com.example.zk2cr;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.List;

public class MusicAdapter extends BaseAdapter {
    Context context;
    List<Music> list;

    public MusicAdapter(Context context, List<Music> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(context).inflate(R.layout.item_music,null);
        TextView tvName = convertView.findViewById(R.id.tv_name);
        TextView tvDuration = convertView.findViewById(R.id.tv_duration);

        tvName.setText(list.get(position).getName()+"");
        SimpleDateFormat format = new SimpleDateFormat("mm:ss");//分：秒的样式
        tvDuration.setText(format.format(list.get(position).getDuration())+"");

        return convertView;
    }


}
